package com.hwadee.teachingprocessmanagementsystem.controller.student;

import com.hwadee.teachingprocessmanagementsystem.dataform.StudentClassroomRequestForm;
import com.hwadee.teachingprocessmanagementsystem.dto.student.StudentClassroomApplicationDto;
import com.hwadee.teachingprocessmanagementsystem.entity.ClassroomRequest;
import com.hwadee.teachingprocessmanagementsystem.entity.Student;
import com.hwadee.teachingprocessmanagementsystem.service.base.ClassroomRequestService;
import com.hwadee.teachingprocessmanagementsystem.service.student.StudentService;
import com.hwadee.teachingprocessmanagementsystem.util.result.DataResult;
import com.hwadee.teachingprocessmanagementsystem.util.result.code.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Description: 学生教室申请控制器，负责学生的教室申请请求
 * @Author: Jukomu
 * @Package: com.hwadee.teachingprocessmanagementsystem.controller.student
 * @Project: TeachingProcessManagementSystem
 * @name: ClassroomsController
 * @Date: 2024/7/12-9:05
 * @Filename: ClassroomsController
 */
@RestController("StudentClassroomsController")
@RequestMapping("student/classroom")
public class ClassroomsController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private ClassroomRequestService classroomRequestService;
    /**
     * 教室申请接口
     * @return
     */
    @GetMapping("application")
    public DataResult getApplication(@RequestParam("student-number") String studentNumber, @RequestParam("campusId") String campusId) {
        System.out.println(studentNumber);
        System.out.println(campusId);
        Student student = new Student();
        student.setStudentNumber(studentNumber);
        StudentClassroomApplicationDto studentClassroomApplicationDto = new StudentClassroomApplicationDto();
        if (Objects.equals(campusId, "")) {
            //校区为空
            studentClassroomApplicationDto = this.studentService.getStudentClassroomApplicationDto(null, student);
            return DataResult.successByData(studentClassroomApplicationDto);
        }
        studentClassroomApplicationDto = this.studentService.getStudentClassroomApplicationDto(campusId, student);
        return DataResult.successByData(studentClassroomApplicationDto);
    }


    @PostMapping("application")
    public DataResult postApplication(@RequestBody StudentClassroomRequestForm form) {
        ClassroomRequest classroomRequest = new ClassroomRequest();
        classroomRequest.setClassroomId(Integer.valueOf(form.getClassroomId()));
        classroomRequest.setDate(Long.valueOf(form.getDate()));
        classroomRequest.setHeadPersonId(form.getHeadPersonId());
        if (Objects.equals(form.getType(), "0")) {
            classroomRequest.setRequestPerson(form.getRequestId());
        } else {
            classroomRequest.setRequestGroup(form.getRequestId());
        }
        classroomRequest.setStatus("审核中");
        classroomRequest.setTimeSlot(form.getStartTime()+"-"+form.getEndTime());
        if (this.classroomRequestService.insert(classroomRequest) > 0) {
            return DataResult.succ();
        }
        return DataResult.errByErrCode(Code.ERROR);
    }

    /**
     * 我的申请接口
     * @return
     */
    @RequestMapping("my-application")
    public DataResult myApplication() {
        return DataResult.succ();
    }
}
